package cn.com.mr;

import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class IntSumReducer extends
		Reducer<Text, IntWritable, Text, IntWritable> {

	IntWritable cnt = new IntWritable();

	@Override
	protected void reduce(Text key, Iterable<IntWritable> values,
			Context context) throws IOException, InterruptedException {

		// 1. 定义一个统计变量
		int count = 0;
		// 2. 获取一个values,进行统计
		Iterator<IntWritable> it = values.iterator();
		while (it.hasNext()) {
			IntWritable value = it.next();
			count = count + value.get();
		}

		cnt.set(count);
		// 3. 输出
		context.write(key, cnt);
	}
}
